package com.gxa.service.impl;

import com.gxa.domain.dto.MaterialDTO;
import com.gxa.domain.entity.Material;
import com.gxa.domain.vo.MaterialVO;
import com.gxa.mapper.MaterialMapper;
import com.gxa.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * User: gxb
 * Date: 2024/07/18  9:16
 * Description:
 * Version: V1.0
 */
@Service//IOC注解  把当前service创建一个对象 交给spring进行管理
@Transactional//开启事务 事务是指逻辑上的一组要操作，要么都成功，要么都是失败
public class MaterialServiceImpl implements MaterialService {
    @Autowired
    private MaterialMapper materialMapper;
    @Override
    public void insertMaterial(Material material) {
        materialMapper.insertMaterial(material);
    }

    @Override
    public MaterialVO findMaterialById(Long id) {
        if(id==null){
            return null;
        }
        return materialMapper.findMaterialById(id);
    }

    @Override
    public List<MaterialVO> findMaterialAll() {
        return materialMapper.findMaterialAll();
    }

    @Override
    public void updateMaterial(Material material) {
        materialMapper.updateMaterial(material);
    }

    @Override
    public void deleteMaterialById(Long id) {
        if(id==null){
            return;
        }
        System.out.println("-------"+id);
        materialMapper.deleteMaterialById(id);
    }

    @Override
    public List<Material> findMaterialByWhere(MaterialDTO materialDTO) {
        return materialMapper.findMaterialByWhere(materialDTO);
    }
}
